<%@page import="java.util.List"%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增部门</title>
</head>

<body>
<style type="text/css"> 
#mytable {   
    padding: 0;
    margin: 0;   
    border-collapse:collapse;
}

td {
    border: 1px solid #C1DAD7;   
    background: #fff;
    font-size:11px;
    padding: 6px 6px 6px 12px;
    color: #4f6b72;
}

td.alt {
    background: #F5FAFA;
    color: #797268;
}

</style>
<%
	List deptNameList = (List)request.getAttribute("deptNameList");
%> 
<form id="form1" name="form1" action="" method="post">
<div>
	<fieldset style="width: 90%;">
					<legend>
						<span><b>部门基本信息</b></span>
					</legend>
					<table width="100%" cellspacing="1" align="center"  border="0" bordercolor="blue">
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">上级部门：</td>
								<td class="alt" style="text-align: left;  padding-left: 3px;padding-top: 5px;" width="15%" >
									<input id="parentName" name="parentName" type="text" value="${deptParenteName}" readonly="readonly" disabled="disabled"/>
									<input id="m2" name="m2" type="hidden" value="${deptId}" readonly="readonly"/>
									<input type="hidden" id="deptId" name="deptId" value="${deptId}"/>
								</td>	
								<td class="alt" align="right" class="tdBackGorund" width="5%">类型：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;" width="15%">
								    <select id="p15" name="p15" style="width: 155px">
										<option value="0">部门</option>		 
										<option value="1">目录</option>										
																										
									</select>
								  							
								</td>				
							
							</tr>						
					
							<tr height="29">								
								<td class="alt" align="right" class="tdBackGorund" width="5%">部门名称：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;" width="15%">
								    <input id="m3" name="m3" type="text" value=""  /><label style="color: red">★</label>	
								    <input id="m4" name="m4" type="hidden" value="" />								
								</td>	
								<td class="alt" align="right" class="tdBackGorund" width="5%">级 &nbsp;&nbsp;&nbsp;&nbsp;别：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;">
									<select id="z4" name="z4" style="width: 155px">
									          <option value="0">--请选择--</option>
											 <c:forEach items="${jiBei}" var="JB" varStatus="i">
										<option value="${JB.z1}">${JB.z3}</option>										
										</c:forEach>																		
									</select>
								</td>
							</tr>
							<!--  
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">部门模板：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
								<input id="modelName" name="modelName" type="text" value="" onclick="showChart()" readonly="readonly"/>
									<input id="m4" name="m4" type="hidden" value="" />
								</td>
								<td class="alt" align="right" class="tdBackGorund" width="5%">部门邮编：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m6" name="m6" type="text" value=""/>
								</td>	
							</tr>
							-->
								<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">部门地址：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m5" name="m5" type="text" value=""/>
								</td>
								<td class="alt" align="right" class="tdBackGorund" width="5%">联系人：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m9" name="m9" type="text" value=""/>
								</td>	
							</tr>
								<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">联系电话：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m10" name="m10" type="text" value=""/>
								</td>
								<td class="alt" align="right" class="tdBackGorund" width="5%">备用电话：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m11" name="m11" type="text" value=""/>
								</td>	
							</tr>
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">QQ号：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m12" name="m12" type="text" value=""/>
								</td>
								<td class="alt" align="right" class="tdBackGorund" width="5%">微信号：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="m13" name="m13" type="text" value=""/>
								</td>	
							</tr>
							<tr><td class="alt" align="right" class="tdBackGorund" width="5%">部门邮编：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%" > 
									<input id="m6" name="m6" type="text" value=""/>
								</td>
								<td class="alt" align="right" class="tdBackGorund" width="5%">采集部门：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%" > 
									<input name="p31" type="radio" value="0"  checked="checked" />否
									<input name="p31"  type="radio"  value="1"  />是
								</td>
							</tr>
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">部门简介：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;" colspan="3">
									  <textarea name="m7" style="width:98%; height:160px;"></textarea>
								</td>
						</tr>
						<tr> 
						    <td colspan="4" align="center"><input type="button" value="保存" onclick="addNew()"/><input type="button" value="返 回" onclick="returnMain()"/></td>
						</tr>
					</table>
				</fieldset>			
</div>
</form>

<!-- <div id="upatediv" style="display: none;background-color: #ffffff;width: 12%;height: 30%;">
 <div align="center">
	<input type="button" id="saveButton" onclick="save();"  value="确定"/>
	<input type="button"  onclick="closeDiv();"  value="取消"/>	
 </div>	
 <div id="menu" align="right" style="width:100%;height: 90%;margin-top: 10px;margin-right: 2px;">
	<ul id="treeDemo" class="ztree"></ul>
  </div>
 
	


</div>
 -->
<div  id="upatediv" style="display: none;background-color: #ffffff;width: 15%;overflow: auto;position: absolute;">
				<ul id="treeDemo" class="ztree"></ul>
			<input type="button" id="saveButton" onclick="save();"  value="确定"/>
	        <input type="button"  onclick="closeDiv();"  value="取消"/>	
			</div>
<script type="text/javascript">




jQuery("document").ready(function(){
	
	treeObj = $.fn.zTree.init($("#treeDemo"), setting);
});

function save() {
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");	
	var nodes = treeObj.getCheckedNodes(true);
	var model = "";
	var modelId = "";
	
	for (var i = 0; i < nodes.length; i++) {
		if(i==(nodes.length-1)){
			if(nodes[i].id != "-1"){			
				  model += nodes[i].name; 	
				  modelId += nodes[i].id;
			}else{
				 modelId += nodes[i].id;
			}
    	}else{
    		if(nodes[i].id != "-1"){			
  			  model += nodes[i].name +","; 	
  			  modelId += nodes[i].id +",";
  		}else{
  			 modelId += nodes[i].id +",";
  		}
    	}
		

	}
	$('#modelName').val(model);
	$('#m4').val(modelId);
	jQuery('#upatediv').trigger('close');
  
};




function zTreeOnClick(event, treeId, treeNode) {
	
    var d = treeNode.id;	  
  $('#deptId').val(d);
  var url1 = ctx+'/ufmDept/ajaxGetTree';
   url1 += '?parentId='+d;
	 jQuery.ajax({
		    url:url1,
		    type: "POST",
		    async:false,
		    success: function(data) {		    
		    	$("#resultList").empty();
  				$("#resultList").html(data);
		    }
		});
  
  
  
};
// zTree
var setting = {
			async: {
				enable: true,
				url:"${pageContext.request.contextPath}/ufmDept/getModelTree",
				autoParam:["id", "level"]
			},
			check: {
				enable: true
			},
		   data: {		
			   simpleData: {
			          enable: true
		           }
	                 }
	//     callback: {
	//	       onClick: zTreeOnClick
	 //          }

};

//构建模板树
function showChart(){
	var width = document.body.clientWidth/4;
	var height = document.body.clientHeight/3;
	jQuery('#upatediv').lightbox_me({
		modalCSS:{top: height,left:width}
     });
}

function closeDiv(){
	jQuery('#upatediv').trigger('close');
}

function addNew(){	
	var deptName = $('#m3').val();	
	<% 
		for(int i = 0; i < deptNameList.size(); i++){
			String deptName = deptNameList.get(i).toString();
			%>
			if(deptName == "<%=deptName%>"){
				alert("部门名称已存在，请重新填写");
				return null;
			}
			<%
		}
	%>
	var flag = true;
	flag = validate();
	if(flag){
		var formObj = document.getElementById("form1");
		formObj.action=ctx+'/ufmDept/addNew';
		formObj.submit();
	}
}

function returnMain(){
	var formObj = document.getElementById("form1");
	formObj.action=ctx+'/ufmDept/findAll';
	formObj.submit();
}

function validate(){	
    var myreg= /^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var mobilephoneReg = /^\d{11}$/;
    var telephoneReg = /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/;
    var userloginReg = /^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9]$/;
    var ww = /^\s*$/;
    
    var numReg = /^[0-9]*$/;
  	if(jQuery("#m3").val() == ""){
		alert("请填写部门名称 ");
		return false;
	}
  	if(ww.test(jQuery("#m3").val())){
  		alert("部门名称不能输入空格 ");
		return false;
  	}

  	if(jQuery("#m6").val()!=""){
		if(!numReg.test(jQuery("#m6").val())){
			alert("请正确填写部门邮编 ");
			return false;
		}
	}
	if(jQuery("#m10").val()!=""){
		if(!mobilephoneReg.test(jQuery("#m10").val()) && !telephoneReg.test(jQuery("#m10").val())){
			alert("请正确填写联系电话(格式: 010-12345678  或 12345678 或  11位数字)");
			return false;
		}
	}
	if(jQuery("#m11").val()!=""){
		if(!telephoneReg.test(jQuery("#m11").val())){
			alert("请正确填写备用电话(格式：010-12345678 或 12345678)");
			return false;
		}
	}
	if(jQuery("#m12").val()!=""){
		if(!numReg.test(jQuery("#m12").val())){
			alert("请正确填写QQ号");
			return false;
		}
	}
	
	return true;
  }
  
</script>
</body>
</html>
